<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/11/5
 * Time: 11:44
 */
class CategoryController extends Controller
{

    private $_title;
    private $_daytime;
    private $_daydate;

    public function init()
    {
        parent::init();
        $__now_time = $_SERVER['REQUEST_TIME'];
        $this->_daytime = date("Y-m-d h:i:s", $__now_time);
        $this->_daydate = date("Y-m-d", $__now_time);
    }

    public function indexAction(){
        //这里用异步调用分类数据，数据用
        $cateArr = array(
            'HDPE' ,
            'LDPE' ,
            'LLDPE',
            'PP',
            'MLLDPE',
        );

        //读取分类筛选
       // $cache_key = "cache_Key_cate";//设置key
       // $catedata = $this->_cache_handler->load($cache_key);//先读缓存

//        if(!empty($catedata)){
//            echo json_encode($catedata);
//            die();
//        }

        $cateurl = _HTTP_CLOUD_HOST."/api/getprice/getCateInfo";
        $cv =array(
            'v' =>1,
        );
        $getcate = Tools::https_request($cateurl,$cv);
        $cate= json_decode($getcate,true);


        foreach($cate['data'] as $var){

            $catelist[$var['cate_name']]['num'] = $var['num'];
        }

        $quota = new QuotationModel();

        foreach($cateArr as $key=>$var){
            $list[$var]['key'] =$var;
            $list[$var]['num'] = $catelist[$var]['num']+$quota->getTotalById("product_cates.cate_name like '%{$var}%'");
        }

//        $this->_cache_handler->put($cache_key,$catelist,7200);
        echo json_encode($list);
        die();
    }


}